package com.Ngbussiness.server;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.Ngbussiness.dao.membersDao;
import com.Ngbussiness.dao.impl.membersDaoImpl;
import com.Ngbussiness.util.DataTools;


public class UpdatememinforServlet extends HttpServlet {

	/**
	 * The doGet method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to get.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		response.setContentType("text/html");
		response.setCharacterEncoding("UTF-8");
		PrintWriter out = response.getWriter();
		//用户输入所需要更新的数据
		int id=Integer.parseInt(request.getParameter("id"));
		String name=request.getParameter("name");
//		String password=request.getParameter("password");
		String sex=request.getParameter("sex");
		String provincename=request.getParameter("province");
		String cityname=request.getParameter("city");
		int cityId=0;
		int provinceId=0;
		membersDao members = new membersDaoImpl();
		List list1=members.getcityId(DataTools.HexStringhtoString(cityname));
		System.out.println(DataTools.HexStringhtoString(cityname));
		if(list1.size()>0)
		{
			HashMap adu=(HashMap)list1.get(0);
			cityId=Integer.parseInt(adu.get("Id").toString());
			System.out.println(cityId);
		}
		List list2=members.getcityId(DataTools.HexStringhtoString(provincename));
		if(list2.size()>0)
		{
			HashMap adu=(HashMap)list2.get(0);
			provinceId=Integer.parseInt(adu.get("Id").toString());
		}
//		String mobel=request.getParameter("mobel");
		String email=request.getParameter("email");
//		String ture_name=request.getParameter("ture_name");
//		String id_number=request.getParameter("id_number");
//		String address=request.getParameter("address");
		String bank_card=request.getParameter("bank_card");
//		String pay_password=request.getParameter("pay_password");
		boolean b1=members.updatemembers(DataTools.HexStringhtoString(name),DataTools.HexStringhtoString(sex),
				cityId,provinceId,email,bank_card,id);
		if(b1==true){
			out.println("success");
		}
		else
		{
			out.println("error");
		}
		out.flush();
		out.close();

	}

	/**
	 * The doPost method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to post.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
            doGet(request,response);
		
	}

}
